<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<body>
  <script>

  /*   fn()
    function fn() {
        
    }

    var fn2 = function () {
        
    } */







   function fn1() {
        var a = 2;
        var fn2 = function () {
            a++;
            console.log(a);
        }
        return fn2;
    }
    var f = fn1();
    f();
    f();
    // f = null
    f = 1


    function showDedelay (time, msg) {
        var timoutId = setTimeout(() => {
            alert(msg)
        }, time)
        // return timeoutId
    }
    const timeoutId = showDelay(1000, 'abc')
    // clearTimeout(timeoutId) 

    // 题1
    
    /* for ( var i = 0 ; i < 5; i++ ) {
        setTimeout(function(){
            console.log(i);
        }, 0);
    }  */
   
   // 55555

    // 题2
    
    /* for ( let i = 0 ; i < 5; i++ ) {
        setTimeout(function(){
            console.log(i);
        },0);
    } */
    // 01234 
   

    // 题3
    
    /* for ( var i = 0 ; i < 5; i++ ) {
        (function(j){
            setTimeout(function(){
                console.log(j);
            }, 0);
        })(i);
    }  */
    // 01234
   


    // 题4
    
    /* var scope = 'global scope'
    function checkscope(){
        var scope = 'local scope'
        return function f(){
            console.log(scope)
        }
    }
    var f = checkscope()
    console.log(f()) // local scope undfined
   */

   // 题5
   
   /* var name = 'jerry'
    var obj = {  
        name : 'tom',  
        sayName(){  
            return function(){  
                console.log(this.name);  
            }
        }   
    }
    obj.sayName()() */

    // function fn (){}
    // fn()
    // window.fn()
  

  </script>
</body>
</html>